<!DOCTYPE html>
<html>
<head>
	<title>PHP网站开发实例教程 - 传智商城</title>
	<meta charset="UTF-8">
	<link rel="stylesheet" href="./Public/Home/css/style.css"/>
	<script src="./Public/Common/js/jquery.min.js"></script>
</head>
<body>
<?php include_once 'top.php'; ?>    
<div class="box">
<?php include_once 'header.php';?>
<?php include_once 'nav.php'; ?>
<div class="goodsinfo">
	<div class="now_cat">当前位置：&nbsp;<a 
		href="/Index/find/cid/14.html">图书</a>&nbsp;&gt;&nbsp;<a 
		href="/Index/find/cid/16.html">IT类</a>&nbsp;&gt;&nbsp;<a 
		href="/Index/find/cid/17.html">PHP书籍</a>&nbsp;&gt;&nbsp;PHP网站开发实例教程</div>
        <?php
         $id=isset($_GET['id'])?$_GET['id']:1;
         //三小步：
         //1.连接数据库
         $link=  mysqli_connect("localhost", "root", "");
         mysqli_select_db($link, "itcast");
         mysqli_set_charset($link, "utf8");
         //2.写SQL语句 （操作数据库表的sql语句），首先写SQL模板 SELECT * FROM shop_goods WHERE id=1; 
        $sql="SELECT * FROM shop_goods WHERE id=$id;";
         //3.执行查询并返回结果;//mysqli_query(连接资源,查询语句)，如果查询语句为select ，成功返回数据资源，失败返回false；如果查询语句为insert update delete ，成功返回true 失败返回false
        $result=  mysqli_query($link, $sql);
//        var_dump($result);
//        echo "<br>";
        $row= mysqli_fetch_assoc($result);
//        $id=$row['id'];
        $name=$row['name'];
        $price=$row['price'];
        $sn=$row['sn'];
        $thumb=$row['thumb'];
        $stock=$row['stock'];
        $desc=$row['desc'];
        ?>
    <div class="pic left">		<img width="350" height="300" src="./Public/Uploads/big/<?php echo $thumb; ?>" /></div>
	<div class="info left"><h1><?php echo $name; ?></h1><table>
		<tr><th>售 价：</th><td><span class="price"><?php echo $price; ?></span></td></tr>
		<tr><th>商品编号：</th><td><?php echo $sn; ?></td></tr>
		<tr><th>累计销量：</th><td>1000</td></tr>
		<tr><th>评 价：</th><td>1000</td></tr>
		<tr><th>配送至：</th><td>北京（免运费）</td></tr>
		<tr><th>购买数量：</th>
                    <td>
		    <form action="addcart.php" method="post">
                        <input type="hidden" name="gid" value="<?php echo $id;?>">
			<input type="button" value="-" class="cnt-btn" />
			<input type="text" name="num" value="1" id="num" class="num-btn" />
			<input type="button" value="+" class="cnt-btn" />（库存：107）
                    </td>
                </tr>
		<tr>
                    <td colspan="2" class="button">
                        <!--<a href="#" id="buy">立即购买</a>-->
                        <input type="submit" id="buy" value="加入购物车"/>
                    </form>
                    <form method="post" action="/Order/buy.html" id="form_buy">     
                        <input type="submit" id="addCart" value="立即购买"/>
                        <!--<a href="#" id="addCart">加入购物车</a>-->
                    </td>
                </tr>
	    </table>
        </div>
		
			<input type="hidden" name="id" value="45">
			<input type="hidden" name="num" value="" id="form_num">
		        <input type="hidden" name="__hash__" value="baf5a19ef959e3bb229e701abe5e2e4c_35d2c5e315602ee45ddfbdead1cec84c" />
                    </form>
		<div class="clear"></div>
	<div class="goods-slide left"><div class="title">相关商品推荐</div>
		<ul class="item left">
			<li><a href="/Index/goods/id/45.html" target="_blank"><img src="./Public/Uploads/small/2015-05/11/5550444272f89.png"></a></li>
			<li class="goods"><a href="/Index/goods/id/45.html" target="_blank">PHP网站开发实例教程</a></li>
			<li class="price">￥48.80</li>
		</ul><ul class="item left">
			<li><a href="/Index/goods/id/50.html" target="_blank"><img src="./Public/Uploads/small/2015-05/11/5550449f1d984.jpg"></a></li>
			<li class="goods"><a href="/Index/goods/id/50.html" target="_blank">PHP程序设计高级教程</a></li>
			<li class="price">￥45.00</li>
		</ul>	</div>
	<div class="desc left">
            <div class="title">商品详情</div><div class="content">
                <?php echo $desc; ?>
            </div>
        </div>
	<div class="clear"></div>
</div>
<script>
//导航条选中效果
$("#Index_find").addClass("category-curr");
//购买数量加减
$(".cnt-btn").click(function(){
	var num = parseInt($("#num").val());
	if ($(this).val() === '-') {
		if ( num=== 1) return;
		$("#num").val(num-1);
	}else if ($(this).val() === '+') {
		if (num === 107) return;
		$("#num").val(num+1);
	}
});
//自动纠正购买数量
$("#num").keyup(function(){
	var num = parseInt($(this).val());
	if(num<1){ 
		$(this).val(1);
	}else if(num > 107){
		$(this).val(107);
	}
});
//添加购物车
$("#addCart").click(function(){
	var url = "/Cart/add/id/45/num/_NUM_.html";
	window.location.href = url.replace("_NUM_",$("#num").val());
});
//购买
$("#buy").click(function(){
	$("#form_num").val($("#num").val());
	$("#form_buy").submit();
});
</script>
	<div class="service">
		<ul><li>购物指南</li><li>配送方式</li><li>支付方式</li>
			<li>售后服务</li><li>特色服务</li><li>网络服务</li>
		</ul>
	</div>
	<div class="footer">传智商城·本项目仅供学习使用</div>
</div>
</body>
</html>